#!/usr/bin/env python
#-*- coding:utf-8 -*-
# author:Administrator
# datetime:2019/11/25 11:15
# software: PyCharm
# Email:zhou.haitao@technosolutions.cn
import os
import pandas as pd


__auther__ = "Kael"

RAW_FILE_PATH= "./data_within"

TARGET_FILE_NAME="./醛酮target.csv"
HEAD_TITLE = "时间,站点,甲醛,乙醛,丙烯醛,丙酮,丙醛,丁烯醛,甲基丙烯醛,2-丁酮,正丁醛,苯甲醛,戊醛,间甲基苯甲醛,己醛,大气压（kPa）,气温（℃）,湿度（%）,采样期间主导风向\r"

def station_name(sheet_name):
    if sheet_name==0:
        return   "阅海楼（背景点）"
    elif sheet_name==1:
        return "德源药业"
    elif sheet_name==2:
        return "胡沟管理处"
    else:
        return "矿山设计院"



def signal_file_process(file_name,sheet_name,sigle_station=True):

    df = pd.read_excel(file_name,sheet_name)
    data=[]

    data.append("20"+ df.iloc[8,1][0:12])
    if sigle_station:
        data.append("市站")
    else:
        data.append(station_name(sheet_name))

    data.append( df.iloc[10,4])

    data.append( df.iloc[11,4])
    data.append( df.iloc[12,4])
    data.append( df.iloc[13,4])
    data.append( df.iloc[14,4])
    data.append(df.iloc[15,4])
    data.append( df.iloc[16,4])
    data.append(df.iloc[17,4])
    data.append(df.iloc[18,4])
    data.append(df.iloc[19,4])
    data.append(df.iloc[20,4])
    data.append( df.iloc[21,4])
    data.append( df.iloc[22,4])

    data.append( df.iloc[4,2])
    data.append( df.iloc[4,4])
    data.append( df.iloc[4,6])
    data.append( df.iloc[5,2])

    return str(data).rstrip(']').lstrip('[')+"\r"

def main_process(files_path,f_obj):
    for file_name in os.listdir(files_path):
        print(file_name)
        file_path = os.path.join(files_path,file_name)

        if "其它" in file_name:
            print(file_name)
            for i in range(4):
                f_obj.write(signal_file_process(file_path, i, False))
        else:
            f_obj.write(signal_file_process(file_path,0,True).replace("'","").replace("'",""))

if __name__ == '__main__':
    # print(signal_file_process("./data_within/连云港4月13日-醛酮.xlsx", 0,True))

    f_obj = open(TARGET_FILE_NAME,"w")
    f_obj.write(HEAD_TITLE)

    main_process(RAW_FILE_PATH,f_obj)
    f_obj.close()

